const query = require('./query')

const querySwiper = async () => {
  const sql = 'select swiper_id as id,swiper_imgUrl as imgUrl,goods_id from swiper where swiper_status = 1'
  try {
    const result = await query(sql)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}

const queryHomeByHomeName = async (home_name) => {
  const sql = `select 
  a.home_type as type,
  a.home_imgUrl,
  d.goods_image_path,
  c.goods_name as title,
  c.goods_desc,
  b.goods_id
  from home a 
  join goodsInfo b
  join goods c
  join goods_image d
  where home_status = 1
  and a.goodsInfo_id = b.goodsInfo_id
  and b.goods_id = c.goods_id
  and b.goods_image_id = d.goods_image_id
  and a.home_name = ?
  `
  try {
    const result = await query(sql, home_name)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}

const queryPromo = async () => {
  const sql = `select home_id,home_imgUrl as imgUrl,goods_id from home where home_name = '促销'`
  try {
    const result = await query(sql)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}

const queryBanner = async () => {
  const sql = `select home_id,home_imgUrl as imgUrl,goods_id from home where home_name = '横幅'`
  try {
    const result = await query(sql)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}
module.exports = {
  querySwiper,
  queryHomeByHomeName,
  queryPromo,
  queryBanner
}